package top.rish.converter.core.annotation.handler;

import top.rish.converter.core.utils.ObjKit;
import top.rish.converter.core.annotation.EnumConverter;
import top.rish.converter.core.base.DictEntity;
import top.rish.converter.core.info.FieldWrap;
import top.rish.converter.core.info.MetaMap;
import top.rish.converter.core.utils.RefKit;

import java.util.Objects;

public class EnumConverterHandlerDict implements DictConvertHandler<EnumConverter> {
    @Override
    public void convert(MetaMap mateMap,
                        DictEntity entity,
                        Object value, FieldWrap fieldWrap,
                        EnumConverter convert) {
        Class<? extends Enum<?>> enumClass = convert.value();
        Enum<?> ev = RefKit.getEnumByValue(enumClass, value);
        if(ObjKit.isNotEmpty(ev)){
            mateMap.set(fieldWrap.getName()+"Name", Objects.toString(ev));
        }
    }
}
